/**
 * Copyright (c) 2014-2015, Suredy technology Co., Ltd. All rights reserved.
 * @author ZhangMaoren 
 * @since 2015年4月27日
 * @version 0.1
 */
package com.suredy.base.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.suredy.core.model.BaseModel;


/**
 * @author ZhangMaoren
 *
 */
@Entity
@Table(name = "T_SECURITY_ROLE2PERMISSION")
public class Role2Permission extends BaseModel {


	/**
	 * 
	 */
	private static final long serialVersionUID = -4529646227556472193L;

	
	@Column(name = "ROLEID", length = 32)
	private String roleId;
	
	
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "PERMISSIONID")
	private Permission rolePermission;
	
	/**
	 * @return the roleId
	 */
	public String getRoleId() {
		return roleId;
	}

	
	/**
	 * @param roleId the roleId to set
	 */
	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	

	
	/**
	 * @return the rolePermission
	 */
	public Permission getRolePermission() {
		return rolePermission;
	}


	
	/**
	 * @param rolePermission the rolePermission to set
	 */
	public void setRolePermission(Permission rolePermission) {
		this.rolePermission = rolePermission;
	}


	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Role2Permission that = (Role2Permission) o;
		if (id != null ? !id.equals(that.id) : that.id != null){
			return false;
		}
		if (rolePermission != null ? !rolePermission.equals(that.rolePermission) : that.rolePermission != null){
			return false;
		}
		if (roleId != null ? !roleId.equals(that.roleId) : that.roleId != null){
			return false;
		}

		return true;
	}

	@Override
	public int hashCode() {
		int result = (id != null ? id.hashCode() : 0);
		result += (roleId != null ? roleId.hashCode() : 0);
		result += (rolePermission != null ? rolePermission.hashCode() : 0);
		return result;
	}

	@Override
	public String toString() {
		return "Role2Permssion[id=" + id + ", roleId=" + roleId + ", rolePermission="
				+ rolePermission + "]";
	}

}
